home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FLI106C.ZIP;1 / FLIMOUSE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  7.8 KB  |  399 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // Transparent Mouse Interface
  8. //
  9.  
  10. #include "fli.h"
  11.  
  12. #ifdef __BCPLUSPLUS__
  13. #pragma hdrstop
  14. #if defined(__SMALL__) || defined(__TINY__) || defined(__MEDIUM__)
  15. #pragma option -Od
  16. #endif
  17. #endif
  18.  
  19. #include <dos.h>
  20. #include <mem.h>
  21. #include <bios.h>
  22. #include <signal.h>
  23.  
  24. int MouseEvent=0;
  25. int MouseButtonStatus=0;
  26. int MouseHorizontal=0;
  27. int MouseVertical=0;
  28.  
  29. int DoubleClickMemory=0;
  30. long DoubleClickTimer=0;
  31.  
  32. int MouseDoubleClickFactor=10;
  33. int MouseRepeatDelay=3;
  34. int MouseRepeatSpeed=0;
  35.  
  36. int DoubleClickHorizontal=0;
  37. int DoubleClickVertical=0;
  38.  
  39. int MouseAvailable;
  40.  
  41. struct _Queue
  42. {
  43.   int MouseEvent;
  44.   int MouseButtonStatus;
  45.   int MouseHorizontal;
  46.   int MouseVertical;
  47. } MouseQueue[200];
  48.  
  49. int MouseQueueCount=0;
  50.  
  51. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  52. //
  53. // MouseHandler()
  54. //
  55. // The memory resident mouse event handler
  56. //
  57. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  58.  
  59. #pragma saveregs
  60.  
  61. void huge MouseHandler()
  62. {
  63.   int MouseEvent;
  64.   int MouseButtonStatus;
  65.   int MouseHorizontal;
  66.   int MouseVertical;
  67.  
  68.   MouseEvent=_AX;
  69.   MouseButtonStatus=_BX;
  70.  
  71.   if (!_CX)
  72.     MouseHorizontal=0;
  73.   else
  74.     MouseHorizontal=_CX/8;
  75.  
  76.   if (!_DX)
  77.     MouseVertical=0;
  78.   else
  79.     MouseVertical=_DX/8;
  80.  
  81.   if (MouseEvent&MouseLeftButtonRelease)
  82.   {
  83.     if (DoubleClickMemory)
  84.     {
  85.       if (DoubleClickTimer>biostime(0,0))
  86.       {
  87.         if (DoubleClickHorizontal==MouseHorizontal &&
  88.           DoubleClickVertical==MouseVertical)
  89.           MouseEvent|=MouseDoubleClick;
  90.         DoubleClickMemory=0;
  91.       }
  92.       else
  93.       {
  94.         DoubleClickHorizontal=MouseHorizontal;
  95.         DoubleClickVertical=MouseVertical;
  96.         DoubleClickMemory=1;
  97.         DoubleClickTimer=biostime(0,0)+MouseDoubleClickFactor;
  98.       }
  99.     }
  100.     else
  101.     {
  102. ReReset:
  103.       DoubleClickHorizontal=MouseHorizontal;
  104.       DoubleClickVertical=MouseVertical;
  105.       DoubleClickMemory=1;
  106.       DoubleClickTimer=biostime(0,0)+MouseDoubleClickFactor;
  107.     }
  108.   }
  109.  
  110.   if (MouseQueueCount>=195)
  111.     return; // prevents overfill of buffer
  112.  
  113.   MouseQueue[MouseQueueCount].MouseEvent=MouseEvent;
  114.   MouseQueue[MouseQueueCount].MouseButtonStatus=MouseButtonStatus;
  115.   MouseQueue[MouseQueueCount].MouseHorizontal=MouseHorizontal;
  116.   MouseQueue[MouseQueueCount].MouseVertical=MouseVertical;
  117.  
  118.   MouseQueueCount++;
  119. }
  120.  
  121. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  122. //
  123. // class MouseConnections
  124. //
  125. // This class connects and disconnects the memory resident mouse handling
  126. // before the program starts and after the program exits
  127. //
  128. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  129.  
  130. class MouseConnections
  131. {
  132.   public:
  133.  
  134.   MouseConnections()
  135.   {
  136.     _AX=0;
  137.     __int__(0x33);
  138.  
  139.     if (!_AX)
  140.       MouseAvailable=0;
  141.     else
  142.     {
  143.       MouseAvailable=1;
  144.  
  145.       _DX=FP_OFF(MouseHandler);
  146.       _ES=FP_SEG(MouseHandler);
  147.  
  148.       _AX=0x0c;
  149.       _CX=0x7f;
  150.  
  151.       __int__(0x33);
  152.       MouseEvent=0;
  153.  
  154.       int Calc=(BlazeClass::WhatHeight()-1)*8;
  155.  
  156.       _CX=0;
  157.       _DX=Calc;
  158.       _AX=8;
  159.       __int__(0x33);
  160.     }
  161.   }
  162.  
  163.   ~MouseConnections()
  164.   {
  165.     if (MouseAvailable)
  166.     {
  167.       _AX=0;
  168.       __int__(0x33);
  169.     }
  170.   }
  171. };
  172.  
  173. static MouseConnections MakeTheConnection;
  174.  
  175. static int MouseVisible=0;
  176.  
  177. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  178. //
  179. // MouseHide()
  180. //
  181. // Hide the mouse
  182. // Should be used before any text writes
  183. //
  184. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  185.  
  186. void MouseHide()
  187. {
  188.   if (MouseAvailable && MouseVisible)
  189.   {
  190.     _AX=2;
  191.     __int__(0x33);
  192.     MouseVisible=0;
  193.   }
  194. }
  195.  
  196. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  197. //
  198. // MouseShow()
  199. //
  200. // Show the mouse
  201. //
  202. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  203.  
  204. void MouseShow()
  205. {
  206.   if (MouseAvailable && !MouseVisible)
  207.   {
  208.     _AX=1;
  209.     __int__(0x33);
  210.     MouseVisible=1;
  211.   }
  212. }
  213.  
  214. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  215. //
  216. // MousePosition()
  217. //
  218. // Position the mouse
  219. //
  220. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  221.  
  222. void MousePosition(int X,int Y)
  223. {
  224.   int NewX=X*8;
  225.   int NewY=Y*8;
  226.  
  227.   if (MouseAvailable)
  228.   {
  229.     _AX=4;
  230.     _CX=NewX;
  231.     _DX=NewY;
  232.     __int__(0x33);
  233.   }
  234. }
  235.  
  236. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  237. //
  238. // CompleteMouseReset()
  239. //
  240. // Reset the mouse subsystem and memory resident handler
  241. //
  242. // SHOULD NOT BE USED UNLESS YOU KNOW THE CONSEQUENCES -- THIS FUNCTION
  243. // IS ONLY USED THROUGH THE MOUSERESTART() AND BLAZE CLASS EXTENDED MODE
  244. // SWITCHING FUNCTIONS
  245. //
  246. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  247.  
  248. void CompleteMouseReset()
  249. {
  250.   _AX=0;
  251.   __int__(0x33);
  252.  
  253.   if (!_AX)
  254.   {
  255.     MouseAvailable=0;
  256.     return;
  257.   }
  258.  
  259.   MouseAvailable=1;
  260.  
  261.   _DX=FP_OFF(MouseHandler);
  262.   _ES=FP_SEG(MouseHandler);
  263.  
  264.   _AX=0x0c;
  265.   _CX=0x7f;
  266.  
  267.   __int__(0x33);
  268.   MouseEvent=0;
  269.  
  270.   MouseVisible=0;
  271.   MouseQueueCount=0;
  272.  
  273.   int Calc=(BlazeClass::WhatHeight()-1)*8;
  274.  
  275.   _CX=0;
  276.   _DX=Calc;
  277.   _AX=8;
  278.   __int__(0x33);
  279. }
  280.  
  281. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  282. //
  283. // MouseShutDown()
  284. //
  285. // Completely shuts down the mouse subsystem
  286. //
  287. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  288.  
  289. void MouseShutDown()
  290. {
  291.   if (MouseAvailable)
  292.   {
  293.     _AX=0;
  294.     __int__(0x33);
  295.   }
  296.   MouseAvailable=0;
  297. }
  298.  
  299. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  300. //
  301. // MouseReStart()
  302. //
  303. // Completely shuts down the mouse subsystem
  304. //
  305. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  306.  
  307. void MouseReStart()
  308. {
  309.   CompleteMouseReset();
  310. }
  311.  
  312. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  313. //
  314. // MouseButtons()
  315. //
  316. // Checks the mouse button status
  317. //
  318. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  319.  
  320. int MouseButtons()
  321. {
  322.   if (MouseAvailable)
  323.   {
  324.     _AX=3;
  325.     __int__(0x33);
  326.     return _BX;
  327.   }
  328.   return 0;
  329. }
  330.  
  331. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  332. //
  333. // GetMouseQueue()
  334. //
  335. // Grabs a mouse event from the mouse queue
  336. //
  337. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  338.  
  339. void GetMouseQueue()
  340. {
  341.   if (!MouseQueueCount)
  342.     MouseEvent=0;
  343.   else
  344.   {
  345.     MouseEvent=MouseQueue[0].MouseEvent;
  346.     MouseButtonStatus=MouseQueue[0].MouseButtonStatus;
  347.     MouseHorizontal=MouseQueue[0].MouseHorizontal;
  348.     MouseVertical=MouseQueue[0].MouseVertical;
  349.     if (MouseQueueCount==1)
  350.       MouseQueueCount=0;
  351.     else
  352.       memmove(&MouseQueue[0],&MouseQueue[1],(--MouseQueueCount)*sizeof(_Queue));
  353.   }
  354. }
  355.  
  356. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  357. //
  358. // FlushMouseQueue()
  359. //
  360. // Flushes the mouse queue
  361. //
  362. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  363.  
  364. void FlushMouseQueue()
  365. {
  366.   MouseQueueCount=0;
  367.   DoubleClickMemory=0;
  368. }
  369.  
  370. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  371. //
  372. // MouseLocate()
  373. //
  374. // Load the current mouse location
  375. //
  376. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  377.  
  378. void MouseLocate()
  379. {
  380.   if (MouseAvailable)
  381.   {
  382.     _AX=3;
  383.     __int__(0x33);
  384.     if (!_CX)
  385.       MouseHorizontal=0;
  386.     else
  387.       MouseHorizontal=_CX/8;
  388.  
  389.     if (!_DX)
  390.       MouseVertical=0;
  391.     else
  392.       MouseVertical=_DX/8;
  393.   }
  394. }
  395.  
  396. #pragma warn .par
  397. #pragma warn .use
  398.  
  399.